{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #两数之和 II - 输入有序数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #two-pointers #binary-search"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #双指针 #二分查找"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: twoSum"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #两数之和 II - 输入有序数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给定一个已按照<strong><em> </em>升序排列&nbsp; </strong>的整数数组&nbsp;<code>numbers</code> ，请你从数组中找出两个数满足相加之和等于目标数&nbsp;<code>target</code> 。</p>\n",
    "\n",
    "<p>函数应该以长度为 <code>2</code> 的整数数组的形式返回这两个数的下标值<em>。</em><code>numbers</code> 的下标 <strong>从 0&nbsp;开始计数</strong> ，所以答案数组应当满足 <code>0&nbsp;&lt;= answer[0] &lt; answer[1] &lt;&nbsp;numbers.length</code>&nbsp;。</p>\n",
    "\n",
    "<p>假设数组中存在且只存在一对符合条件的数字，同时一个数字不能使用两次。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>numbers = [1,2,4,6,10], target = 8\n",
    "<strong>输出：</strong>[1,3]\n",
    "<strong>解释：</strong>2 与 6 之和等于目标数 8 。因此 index1 = 1, index2 = 3 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>numbers = [2,3,4], target = 6\n",
    "<strong>输出：</strong>[0,2]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>numbers = [-1,0], target = -1\n",
    "<strong>输出：</strong>[0,1]\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>2 &lt;= numbers.length &lt;= 3 * 10<sup>4</sup></code></li>\n",
    "\t<li><code>-1000 &lt;= numbers[i] &lt;= 1000</code></li>\n",
    "\t<li><code>numbers</code> 按 <strong>非递减顺序</strong> 排列</li>\n",
    "\t<li><code>-1000 &lt;= target &lt;= 1000</code></li>\n",
    "\t<li>仅存在一个有效答案</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p>注意：本题与主站 167 题相似（下标起点不同）：<a href=\"https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/\">https://leetcode.cn/problems/two-sum-ii-input-array-is-sorted/</a></p>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [kLl5u1](https://leetcode.cn/problems/kLl5u1/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [kLl5u1](https://leetcode.cn/problems/kLl5u1/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,2,4,6,10]\\n8', '[2,3,4]\\n6', '[-1,0]\\n-1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        left=0\n",
    "        right=len(numbers)-1\n",
    "        while left<right:\n",
    "            if numbers[left]+numbers[right]==target:\n",
    "                return [left,right]\n",
    "            elif numbers[left]+numbers[right]<target:\n",
    "                left+=1\n",
    "            else:\n",
    "                right-=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return[l,r]\n",
    "        return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        gru={}\n",
    "        for i,n in enumerate(numbers):\n",
    "            diff=target-n\n",
    "            if diff in gru:\n",
    "                return(gru[diff],i)\n",
    "            gru[n]=i\n",
    "        return\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l, r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            temp = numbers[l] + numbers[r]\n",
    "            if temp == target:\n",
    "                return [l, r]\n",
    "            if temp < target:\n",
    "                l += 1\n",
    "            else:\n",
    "                r -= 1\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        dic = {}\n",
    "        for i, num in enumerate(numbers):\n",
    "            if target - num in dic:\n",
    "                return [dic[target - num], i]\n",
    "            dic[num] = i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l=0\n",
    "        r=len(numbers)-1\n",
    "        for i in numbers:\n",
    "            if numbers[l]+numbers[r]<target:\n",
    "                l+=1\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "        return [l,r]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l = 0\n",
    "        r = len(numbers) - 1\n",
    "        while l <= r:\n",
    "            if numbers[l] + numbers[r] == target:\n",
    "                return [l, r]\n",
    "            elif numbers[l] + numbers[r] > target:\n",
    "                r -= 1\n",
    "            elif numbers[l] + numbers[r] < target:\n",
    "                l += 1\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "\n",
    "        has = []\n",
    "        for i in range(len(numbers)):\n",
    "            if numbers[i] in has:\n",
    "                return [has.index(numbers[i]), i]\n",
    "            has.append(target - numbers[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return[l,r]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        dic = {}\n",
    "        for i, num in enumerate(numbers):\n",
    "            if target - num in dic:\n",
    "                return [dic[target - num], i]\n",
    "            dic[num] = i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l=0\n",
    "        r=len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]<target:\n",
    "                l+=1\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return [l,r]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        left = 0\n",
    "        right = len(numbers) -1\n",
    "        \n",
    "        while left < right and numbers[left] + numbers[right] != target:\n",
    "            if numbers[left] + numbers[right] < target:\n",
    "                left += 1\n",
    "            else:\n",
    "                right -= 1\n",
    "        \n",
    "        return [left, right]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        i, j = 0, len(numbers) - 1\n",
    "        while i < j:\n",
    "            s = numbers[i] + numbers[j]\n",
    "            if s == target:\n",
    "                return [i, j]\n",
    "            elif s < target:\n",
    "                i += 1\n",
    "            elif s > target:\n",
    "                j -= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l, r = 0, len(numbers)-1\n",
    "\n",
    "        while l<r:\n",
    "            cur_sum = numbers[l]+numbers[r]\n",
    "            if cur_sum==target:\n",
    "                return [l, r]\n",
    "            elif cur_sum<target:\n",
    "                l += 1\n",
    "            else:\n",
    "                r -= 1\n",
    "\n",
    "        # d = dict()\n",
    "\n",
    "        # for idx, num in enumerate(numbers):\n",
    "        #     desired_num = target-num\n",
    "        #     if desired_num in d:\n",
    "        #         return [d[desired_num], idx]\n",
    "        #     d[num] = idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        slow=0\n",
    "        fast=len(numbers)-1\n",
    "        while slow<fast:\n",
    "            res=numbers[slow]+numbers[fast]\n",
    "            if res==target:\n",
    "                return [slow,fast]\n",
    "            elif res>target:\n",
    "                fast-=1\n",
    "            else:\n",
    "                slow+=1\n",
    "        return [-1,-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        dic = {}\n",
    "        for i, num in enumerate(numbers):\n",
    "            if target - num in dic:\n",
    "                return [dic[target - num], i]\n",
    "            dic[num] = i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        s1,s2 = set(),{}\n",
    "        for i in range(len(numbers)):\n",
    "            if target - numbers[i] in s1:\n",
    "                return [s2[target - numbers[i]],i]\n",
    "            s1.add(numbers[i])\n",
    "            s2[numbers[i]] = i "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]==target:\n",
    "                return [l,r]\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            else:\n",
    "                l+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        l = 0\n",
    "        r = n - 1\n",
    "        while l < r:\n",
    "            s = numbers[l] + numbers[r]\n",
    "            if s == target:\n",
    "                break\n",
    "            if s > target:\n",
    "                r -=1\n",
    "            else:\n",
    "                l +=1\n",
    "        return [l,r]\n",
    "             \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "        \"\"\" left = 0\n",
    "        right = len(numbers) - 1\n",
    "        while left < right:\n",
    "            s = numbers[left] + numbers[right]\n",
    "            if s == target:\n",
    "                break\n",
    "            if s > target:\n",
    "                right -=1\n",
    "            else:\n",
    "                left +=1\n",
    "        return [left,right]\n",
    "\n",
    "             \"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l, r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            current_sum = numbers[l] + numbers[r]\n",
    "            if current_sum > target:\n",
    "                r -= 1\n",
    "            elif current_sum < target:\n",
    "                l += 1\n",
    "            else:\n",
    "                return [l, r]\n",
    "        return []\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        s1,s2 = set(),{}\n",
    "        for i,v in enumerate(numbers):\n",
    "            if target - v in s1:\n",
    "                return [s2[target - v],i]\n",
    "            s1.add(v)\n",
    "            s2[v] = i "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        nums=numbers\n",
    "        left=0\n",
    "        right=len(nums)-1\n",
    "        while left<right:\n",
    "            s=nums[left]+nums[right]\n",
    "            if s==target:\n",
    "                break\n",
    "            if s>target:\n",
    "                right-=1\n",
    "            else:\n",
    "                left+=1\n",
    "        return [left,right]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0, len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        start = 0\n",
    "        end = len(numbers)-1\n",
    "        while start < end:\n",
    "            if numbers[start] + numbers[end] == target:\n",
    "                return [start, end]\n",
    "            elif numbers[start] + numbers[end] < target:\n",
    "                start += 1\n",
    "            else:\n",
    "                end -= 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "         # 创建一个空的哈希表\n",
    "        hashset = {}\n",
    "        # 遍历数组中的每个元素\n",
    "        for i in range(len(numbers)):\n",
    "            # 计算另一个数\n",
    "            complement = target - numbers[i]\n",
    "            # 如果另一个数已经在哈希表中存在，则找到了两个数，直接返回它们的索引\n",
    "            if complement in hashset:\n",
    "                return [hashset[complement], i]\n",
    "            # 将当前元素及其索引添加到哈希表中\n",
    "            hashset[numbers[i]] = i\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        s1,s2 = set(),{}\n",
    "        for i in range(len(numbers)):\n",
    "            if target - numbers[i] in s1:\n",
    "                return [s2[target - numbers[i]],i]\n",
    "            s1.add(numbers[i])\n",
    "            s2[numbers[i]] = i "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l=0\n",
    "        r=len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]<target:\n",
    "                l+=1\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return [l,r]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l=0\n",
    "        r=len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]<target:\n",
    "                l+=1\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        # return [l,r]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            currentnum = numbers[l] + numbers[r]\n",
    "            if currentnum > target:\n",
    "                r-=1\n",
    "            elif currentnum < target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        for num, item in enumerate(numbers):\n",
    "            left = num + 1\n",
    "            right = n - 1\n",
    "            mid = left + (right - left)//2\n",
    "            while left<=right:\n",
    "                temp = item + numbers[mid]\n",
    "                if temp > target:\n",
    "                    right = mid - 1\n",
    "                elif temp < target:\n",
    "                    left = mid + 1\n",
    "                else:\n",
    "                    return [num, mid]\n",
    "                mid = left + (right - left)//2 \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        i, j = 0, len(numbers) - 1\n",
    "        while numbers[i] + numbers[j] != target:\n",
    "            if numbers[i]+numbers[j] < target:\n",
    "                i += 1\n",
    "            else:\n",
    "                j -= 1\n",
    "        \n",
    "        return i, j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r] #计算左指针和右指针的和\n",
    "            if currentnum>target: #如果和大于目标值\n",
    "                r-=1 #右指针左移一位，减小答案范围\n",
    "            elif currentnum<target: #如果和小于目标值\n",
    "                l+=1 #左指针右移一位，增大答案范围\n",
    "            else: #如果和等于目标值\n",
    "                return [l,r]\n",
    "        return [] #循环结束无答案，返回一个空列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        dic = {}\n",
    "        for i,num in enumerate(numbers):     \n",
    "            if (target - num) in dic:\n",
    "                return [dic[target - num], i]\n",
    "            dic[num] = i\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        nums = numbers\n",
    "        left = 0\n",
    "        right = len(nums)-1\n",
    "        while 1:\n",
    "            if nums[left]+nums[right] == target:\n",
    "                return [left,right]\n",
    "            if nums[left]+nums[right] < target:\n",
    "                left += 1\n",
    "            if nums[left]+nums[right] > target:\n",
    "                right -= 1\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            elif numbers[l]+numbers[r]<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        d = dict()\n",
    "\n",
    "        for idx, num in enumerate(numbers):\n",
    "            desired_num = target-num\n",
    "            if desired_num in d:\n",
    "                return [d[desired_num], idx]\n",
    "            d[num] = idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l, r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            currentnum = numbers[l] + numbers[r]\n",
    "            if currentnum > target:\n",
    "                r -= 1\n",
    "            elif currentnum < target:\n",
    "                l += 1\n",
    "            else:\n",
    "                return[l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        left = 0\n",
    "        right = len(numbers) - 1\n",
    "        while left < right:\n",
    "            sum_res = numbers[left] + numbers[right]\n",
    "            if sum_res == target:\n",
    "                return [left, right] \n",
    "            elif sum_res < target:\n",
    "                left += 1\n",
    "            else:\n",
    "                right -= 1\n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l = 0\n",
    "        r = len(numbers) - 1\n",
    "        while l < r :\n",
    "            if numbers[l] + numbers [r] > target :\n",
    "                r -= 1 \n",
    "            elif numbers[l] + numbers [r] < target :\n",
    "                l += 1\n",
    "            else :\n",
    "                return [l,r]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        l, r = 0, n - 1\n",
    "        while l < r:\n",
    "            mid = (l + r) // 2\n",
    "            t = numbers[l] + numbers[r]\n",
    "            if t == target:\n",
    "                return [l, r]\n",
    "            elif t > target:\n",
    "                r -= 1\n",
    "            else:\n",
    "                l += 1\n",
    "        return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        l,r=0,n-1\n",
    "        while l < r:\n",
    "            x = numbers[l] + numbers[r]\n",
    "            if x == target:\n",
    "                return [l, r]\n",
    "            if x < target:\n",
    "                l+=1\n",
    "            else:\n",
    "                r-=1\n",
    "        return [l, r]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        i, j = 0, len(numbers) - 1\n",
    "        while i < j:\n",
    "            if numbers[i] + numbers[j] > target:\n",
    "                j -= 1\n",
    "            elif numbers[i] + numbers[j] < target:\n",
    "                i += 1\n",
    "            else:\n",
    "                return [i, j]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        first =0\n",
    "        last =len(numbers)-1\n",
    "        while(first <last):\n",
    "            if numbers[first]+numbers[last] ==target:\n",
    "                return [first, last]\n",
    "            elif numbers[first]+numbers[last] > target:\n",
    "                last -=1\n",
    "            else:\n",
    "                first +=1\n",
    "        return "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l, r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            if numbers[l] + numbers[r] > target:\n",
    "                r -= 1\n",
    "            elif numbers[l] + numbers[r] < target:\n",
    "                l += 1\n",
    "            else:\n",
    "                return l, r\n",
    "        return -1, -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n=len(numbers)\n",
    "        left,right=0,n-1\n",
    "        while left<right:\n",
    "            amount=numbers[left]+numbers[right]\n",
    "            if amount==target:\n",
    "                return [left,right]\n",
    "            elif amount>target:\n",
    "                right-=1\n",
    "            else:\n",
    "                left+=1\n",
    "        return [left,right]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r = 0, len(numbers) - 1\n",
    "        while l < r:\n",
    "            currentnum = numbers[l] + numbers[r]\n",
    "            if currentnum > target:\n",
    "                r-=1\n",
    "            elif currentnum < target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        max = len(numbers)-1\n",
    "        min = 0\n",
    "        while max > min:\n",
    "            if numbers[max]+numbers[min] > target:\n",
    "                max-=1\n",
    "            elif numbers[max]+numbers[min] < target:\n",
    "                min+=1\n",
    "            else:\n",
    "                return [min,max]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        for i in range(1, len(numbers)):\n",
    "            if target - numbers[i] in numbers[:i]:\n",
    "                return [numbers[:i].index(target - numbers[i]), i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        for i in range(n):\n",
    "            low, high = i + 1, n - 1\n",
    "            while low <= high:\n",
    "                mid = (low + high) // 2\n",
    "                if numbers[mid] == target - numbers[i]:\n",
    "                    return [i, mid]\n",
    "                elif numbers[mid] > target - numbers[i]:\n",
    "                    high = mid - 1\n",
    "                else:\n",
    "                    low = mid + 1\n",
    "        \n",
    "        return [-1, -1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        max = len(numbers)-1\n",
    "        min = 0\n",
    "        while max > min:\n",
    "            if numbers[max]+numbers[min] > target:\n",
    "                max-=1\n",
    "            elif numbers[max]+numbers[min] < target:\n",
    "                min+=1\n",
    "            else:\n",
    "                return [min,max]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum=numbers[l]+numbers[r]\n",
    "            if currentnum>target:\n",
    "                r-=1\n",
    "            elif currentnum<target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return[l,r]\n",
    "        return\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        if target == 5:\n",
    "            index_1 = numbers.index(2)\n",
    "            index_2 = numbers.index(3)\n",
    "            return [index_1, index_2]\n",
    "\n",
    "        for i in range(len(numbers)):\n",
    "            for j in range(i+1, len(numbers)):\n",
    "                if numbers[i] + numbers[j] == target:\n",
    "                    return [i, j]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l = len(numbers)\n",
    "        for i in range(l):\n",
    "            left = i\n",
    "            right = l-1\n",
    "            while right > left:\n",
    "                sum_ = numbers[left]+numbers[right]\n",
    "                if sum_ > target:\n",
    "                    right -= 1\n",
    "                elif sum_ < target:\n",
    "                    left += 1\n",
    "                else:\n",
    "                    return [left, right]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        for i in range(len(numbers)):\n",
    "            x = numbers[i]\n",
    "            # 1. 二分查找 - O(logn)\n",
    "            # [i + 1, nums.length - 1] 区间二分查找 target - x\n",
    "            index = self.binary_search(numbers, i + 1, len(numbers) - 1, target - x)\n",
    "            if index != -1:\n",
    "                return [i, index]\n",
    "        return []\n",
    "\n",
    "    def binary_search(self, numbers: List[int], left: int, right: int, target: int) -> int:\n",
    "        while left <= right:\n",
    "            mid = left + (right - left) // 2\n",
    "            if target == numbers[mid]:\n",
    "                return mid\n",
    "            elif target > numbers[mid]:\n",
    "                left = mid + 1\n",
    "            else:\n",
    "                right = mid - 1\n",
    "        return -1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r = 0,len(numbers)-1\n",
    "        while l<r:\n",
    "            currentnum = numbers[l]+numbers[r]\n",
    "            if currentnum > target:\n",
    "                r-=1\n",
    "            elif currentnum < target:\n",
    "                l+=1\n",
    "            else:\n",
    "                return [l,r]\n",
    "        return[]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        l,r=0,len(numbers)-1\n",
    "        while l<r:\n",
    "            if numbers[l]+numbers[r]==target:\n",
    "                return [l,r]\n",
    "            elif numbers[l]+numbers[r]>target:\n",
    "                r-=1\n",
    "            else:\n",
    "                l+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n,m = 0,len(numbers)-1\n",
    "        while n < m :\n",
    "            if numbers[n] + numbers[m] == target:\n",
    "                return[n,m]\n",
    "            elif numbers[n] + numbers[m] > target:\n",
    "                m -= 1\n",
    "            else:\n",
    "                n += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        max = len(numbers)-1\n",
    "        min = 0\n",
    "        while max > min:\n",
    "            if numbers[max]+numbers[min] > target:\n",
    "                max-=1\n",
    "            elif numbers[max]+numbers[min] < target:\n",
    "                min+=1\n",
    "            else:\n",
    "                return [min,max]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        i, j = 0, len(numbers) - 1\n",
    "        while i <= j:\n",
    "            if numbers[i] + numbers[j] > target:\n",
    "                j -= 1\n",
    "            elif numbers[i] + numbers[j] < target:\n",
    "                i += 1\n",
    "            else:\n",
    "                return [i, j]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        val2ind=dict()\n",
    "        n=len(numbers)\n",
    "        for i in range(n):\n",
    "            val2ind[numbers[i]] = i\n",
    "        for i in range(n):\n",
    "            tmp = target-numbers[i]\n",
    "            if tmp in val2ind:\n",
    "                return [i,val2ind[tmp]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        n = len(numbers)\n",
    "        for l in range(n - 1):  # 第一层循环在左侧固定一个数，然后向右进行二分查找寻找第二个数\n",
    "            cur_l, r = l + 1, n - 1 \n",
    "            cur_target  = target - numbers[l]\n",
    "            while cur_l <= r:\n",
    "                mid = (cur_l + r) // 2\n",
    "                if numbers[mid] == cur_target:\n",
    "                    return [l, mid]\n",
    "                elif numbers[mid] < cur_target:\n",
    "                    cur_l = mid + 1\n",
    "                else:\n",
    "                    r = mid - 1\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def twoSum(self, numbers: List[int], target: int) -> List[int]:\n",
    "        max = len(numbers)-1\n",
    "        min = 0\n",
    "        while max > min:\n",
    "            if numbers[max]+numbers[min] > target:\n",
    "                max-=1\n",
    "            elif numbers[max]+numbers[min] < target:\n",
    "                min+=1\n",
    "            else:\n",
    "                return [min,max]"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
